package day26;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Class c = Class.forName("day26.Person");
        Method m1 = c.getDeclaredMethod("study");
        Method m2 = c.getDeclaredMethod("play", String.class);
        Method m3 = c.getDeclaredMethod("play", String.class, String.class);
        Person p = new Person();
        //m1.invoke(); //用于调用方法的
        Object result1= m1.invoke(p);
        Object result2= m2.invoke(p,"xiao");
        m3.setAccessible(true);
        Object result3= m3.invoke(p,"这个", "电脑");
        System.out.println(result1);
        System.out.println(result2);
        System.out.println(result3);
    }
}
